package live.hotel.entity;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Search implements Serializable {
	private static final long serialVersionUID = -1043260917695322164L;

	private String cityCode; // 城市Code
	private String cityName;
	private double minPrice; // 最低价
	private double maxPrice; // 最高价格
	private String starCode; // 星级
	private String hotelItem; // 酒店名称(选填)
	private String checkInDate; // 入住日期
	private String checkOutDate; // 退房日期
	private int duration; // 停留晚数
	private String rgnLocation; // 行政区
	private String bsnLocation; // 商业区
	private String priceValue;		

	public Search() {
	}

	public Search(String cityCode, double minPrice, double maxPrice,
			String starCode, String checkInDate, String checkOutDate,
			int duration, String rgnLocation, String bsnLocation,
			String hotelItem) {
		this.cityCode = cityCode;
		this.minPrice = minPrice;
		this.maxPrice = maxPrice;
		this.starCode = starCode;
		this.checkInDate = checkInDate;
		this.checkOutDate = checkOutDate;
		this.duration = duration;
		this.rgnLocation = rgnLocation;
		this.bsnLocation = bsnLocation;
		this.hotelItem = hotelItem;
	}

	public String getHotelItem() {
		return hotelItem;
	}

	public void setHotelItem(String hotelItem) {
		this.hotelItem = hotelItem;
	}

	public String getCityCode() {
		return cityCode;
	}

	public void setCityCode(String cityCode) {
		this.cityCode = cityCode;
	}

	public double getMinPrice() {
		return minPrice;
	}

	public void setMinPrice(double minPrice) {
		this.minPrice = minPrice;
	}

	public double getMaxPrice() {
		return maxPrice;
	}

	public void setMaxPrice(double maxPrice) {
		this.maxPrice = maxPrice;
	}

	public String getStarCode() {
		return starCode;
	}

	public void setStarCode(String starCode) {
		this.starCode = starCode;
	}

	public String getCheckInDate() {
		return checkInDate;
	}

	public void setCheckInDate(String checkInDate) {
		this.checkInDate = checkInDate;
	}

	public String getCheckOutDate() {
		return checkOutDate;
	}

	public void setCheckOutDate(String checkOutDate) {
		this.checkOutDate = checkOutDate;
	}

	public int getDuration() {
		long dateIn = dateToLong(checkInDate);
		long dateOut = dateToLong(checkOutDate);
		duration = (int) ((dateOut - dateIn) / (1000 * 60 * 60 * 24) - 1);
		return duration;
	}

	public long dateToLong(String date) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return df.parse(date).getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0L;
		}
	}

	public String getRgnLocation() {
		return rgnLocation;
	}

	public void setRgnLocation(String rgnLocation) {
		this.rgnLocation = rgnLocation;
	}

	public String getBsnLocation() {
		return bsnLocation;
	}

	public void setBsnLocation(String bsnLocation) {
		this.bsnLocation = bsnLocation;
	}

	public String getCityName() {
		return cityName;
	}

	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	public String getPriceValue() {
		return priceValue;
	}

	public void setPriceValue(String priceValue) {
		this.priceValue = priceValue;
	}
}
